﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using _PLATFORM.DATA;

namespace _PLATFORM.WEB.Controllers
{ 
    public class FittingTypeController : Controller
    {
        private eCommPlatformRepoEntities db = new eCommPlatformRepoEntities();

        //
        // GET: /FittingType/
        Guid userID = _PLATFORM.DATA.Custom_Classes.User.UserID;

        public ViewResult Index()
        {
            var fitting_type = db.FITTING_TYPE.Where(f => f.USER_ID == userID);
            return View(fitting_type.ToList());
        }

        //
        // GET: /FittingType/Details/5

        public ViewResult Details(decimal id)
        {
            FITTING_TYPE fitting_type = db.FITTING_TYPE.Find(id);
            return View(fitting_type);
        }

        //
        // GET: /FittingType/Create

        public ActionResult Create()
        {
            //ViewBag.FITTING_TYPE_ID = new SelectList(db.FITTING_TYPE_ASSET, "FITTING_TYPE_ASSET_ID", "NAME");
            ViewBag.USER_ID = userID;
            return View();
        } 

        //
        // POST: /FittingType/Create

        [HttpPost]
        public ActionResult Create(FITTING_TYPE fitting_type)
        {
            if (ModelState.IsValid)
            {
                fitting_type.USER_ID = userID;
                db.FITTING_TYPE.Add(fitting_type);
                db.SaveChanges();
                return RedirectToAction("Index");  
            }

            //ViewBag.FITTING_TYPE_ID = new SelectList(db.FITTING_TYPE_ASSET, "FITTING_TYPE_ASSET_ID", "NAME", fitting_type.FITTING_TYPE_ID);
            ViewBag.USER_ID = userID;
            return View(fitting_type);
        }
        
        //
        // GET: /FittingType/Edit/5
 
        public ActionResult Edit(decimal id)
        {
            FITTING_TYPE fitting_type = db.FITTING_TYPE.Find(id);
            ViewBag.FITTING_TYPE_ID = new SelectList(db.FITTING_TYPE_ASSET, "FITTING_TYPE_ASSET_ID", "NAME", fitting_type.FITTING_TYPE_ID);
            ViewBag.USER_ID = new SelectList(db.FRAMEWORK_USER, "USER_ID", "FIRST_NAME", fitting_type.USER_ID);
            return View(fitting_type);
        }

        //
        // POST: /FittingType/Edit/5

        [HttpPost]
        public ActionResult Edit(FITTING_TYPE fitting_type)
        {
            if (ModelState.IsValid)
            {
                db.Entry(fitting_type).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.FITTING_TYPE_ID = new SelectList(db.FITTING_TYPE_ASSET, "FITTING_TYPE_ASSET_ID", "NAME", fitting_type.FITTING_TYPE_ID);
            ViewBag.USER_ID = new SelectList(db.FRAMEWORK_USER, "USER_ID", "FIRST_NAME", fitting_type.USER_ID);
            return View(fitting_type);
        }

        //
        // GET: /FittingType/Delete/5
 
        public ActionResult Delete(decimal id)
        {
            FITTING_TYPE fitting_type = db.FITTING_TYPE.Find(id);
            return View(fitting_type);
        }

        //
        // POST: /FittingType/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(decimal id)
        {            
            FITTING_TYPE fitting_type = db.FITTING_TYPE.Find(id);
            db.FITTING_TYPE.Remove(fitting_type);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}